$(document).ready(function () {

    $("#banner-add-btn").click(function () {
        window.location.href = "/banner/input.do";
    })
    $("#add-movie-btn").click(function () {
        var object = $(this).parents("tr").find("td:first").text();
        window.location.href = "/movie/input.do?object=" + object;
    })
    // 电影分类增加电影
    $("#category-add-movie-btn").click(function () {
        var ids = new Array();
        $("#category-movies-table tr td input:checkbox:checked").each(function () {
            ids.push($(this).val());
        });
        $("body").showLoading();
        $.ajax({
            'url': "/category/addMovie",
            'data': {'indexCategoryId': indexCategoryId, 'ids': ids.toString()},
            'dataType': 'json',
            'type': 'post',
            'success': function (responseData) {
                $("body").hideLoading();
                var index = 0;
                $("#categoryList a").each(function () {
                    if ($(this).hasClass("active")) {
                        return false;
                    }
                    index++;
                });
                $('#categoryList a').eq(index).trigger("click");
            },
            'error': function () {
                $("body").hideLoading();
            },
            'async': true
        });
    })
    // 删除电影
    $("#movieList").on("click", "button", function () {
        var id = $(this).data("id");
        $("body").showLoading();
        $.ajax({
            'url': "/category/removeMovie",
            'data': {'id': id},
            'dataType': 'json',
            'type': 'GET',
            'success': function (responseData) {
                $("body").hideLoading();
                var index = 0;
                $("#categoryList a").each(function () {
                    if ($(this).hasClass("active")) {
                        return false;
                    }
                    index++;
                });
                $('#categoryList a').eq(index).trigger("click");
            },
            'error': function () {
                $("body").hideLoading();
            },
            'async': true
        });
    });
    // 删除分类
    $("#del-category-btn").on("click", function () {
        $("body").showLoading();
        $.ajax({
            'url': "/category/delete",
            'data': {'indexCategoryId': indexCategoryId},
            'dataType': 'json',
            'type': 'GET',
            'success': function (data) {
                $("body").hideLoading();
                if (data.code == 200) {
                    window.location.href = "/category/list.do";
                }
                else {
                    alert(data.message);
                }
            },
            'error': function () {
                $("body").hideLoading();
            },
            'async': true
        });
    });
    $("#addCategoryBtn").click(function () {
        window.location.href = "/category/input.do";
    })
    $("#user-add-btn").click(function () {
        window.location.href = "/user/input.do";
    })
    var indexCategoryId;
    $("#categoryList").on("click", "a", function () {
        var that = this;
        $("#categoryList a").each(function () {
            $(this).removeClass("active");
        });
        $(that).addClass("active");
        indexCategoryId = $(that).attr("data");
        $("#movieList").empty();
        $("body").showLoading();
        $.ajax({
            'url': "/category/movies",
            'data': {indexCategoryId: indexCategoryId},
            'dataType': 'json',
            'type': 'post',
            'success': function (responseData) {
                $("body").hideLoading();
                var html = "";
                if (responseData.code != 200 || responseData.datas == null) {
                    return
                }
                for (var i = 0; i < responseData.datas.length; i++) {
                    html += ' <div class="mail-item mail-unread mail-info">\n' +
                        '                        <div class="mail-user">' + responseData.datas[i].movie_name + '</div>\n' +
                        '                        <div class="mail-user">￥' + responseData.datas[i].price.toFixed(2) + '</div>\n' +
                        '                        <div class="mail-user">' + responseData.datas[i].create_time + '</div>\n' +
                        '                        <div class="mail-date"><button type="button" class="btn btn-danger" data-id="' + responseData.datas[i].id + '">删除</button></div>\n' +
                        '                    </div>';
                }
                $("#movieList").append(html);
            },
            'error': function () {
                $("body").hideLoading();
            },
            'async': true
        });
    })

    $('#categoryList a:first').trigger("click");

    //banner start

    $('#banner-movies-table :checkbox').on("click",function () {
        var that= this;
        $("#banner-movies-table :checkbox").each(function(){//为页面中每一个checkbox设置点击事件
            if($(this).attr('checked')){ //如果有checkbox状态为选中
                $(this).attr('checked',false); //移除checked属性，改变checkbox状态为未选中(为页面中所有checkbox复选框添加设置)
            }
        });
        $(that).attr('checked','true'); //为当前点击选中的checkbox复选框添加checked属性
    })

    // bander 选择电影
    $("#banner-add-movie-btn").click(function () {
        var id;
        $("#banner-movies-table tr td input:checkbox:checked").each(function () {
           id=$(this).val();
           var name=$(this).parent("td").next().text();
            $("#movieName").val(name);
            $("#movieId").val(id);
        });
    })

  $("#submit-banner-form-btn").click(function () {
      $("body").showLoading();
      $.ajax({
          'url': "/banner/save",
          'data': $("#bannerForm").serialize(),
          'dataType': 'json',
          'type': 'post',
          'success': function (responseData) {
              $("body").hideLoading();
              window.location.href="/banner/list"
          },
          'error': function () {
              $("body").hideLoading();
          },
          'async': true
      });
  })
    //banner end

    $("#userSaveBtn").click(function () {
        var password=$("#password").val();
        var password2=$("#password2").val();
        if(password!=password2){
            alert("密码不一致");
            return;
        }
        $("body").showLoading();
        $.ajax({
            'url': "/user/save",
            'data': $("#userSaveForm").serialize(),
            'dataType': 'json',
            'type': 'post',
            'success': function (responseData) {
                $("body").hideLoading();
                window.location.href="/user/list"
            },
            'error': function () {
                $("body").hideLoading();
            },
            'async': true
        });
    })







    $("#bannerImageForm").dropzone({
        url: "/media/uploadImages",
        maxFilesize: 1,
        addRemoveLinks: true,
        acceptedFiles: ".gif,.jpg,.png",
        success: function (file, data) {
            $("#bannerImage ").val(data.datas[0]);
        },
        init: function (file) {
            console.log(file);
        }
    });
    $("#coverForm").dropzone({
        url: "/media/uploadImages",
        maxFilesize: 5,
        addRemoveLinks: true,
        acceptedFiles: ".gif,.jpg,.png",
        success: function (file, data) {
            $("#logoInput").val(data.datas[0]);
        },
        init: function (file) {
            console.log(file);
        }
    });

    $("#imageForm").dropzone({
        url: "/media/uploadImages",
        maxFilesize: 5,
        addRemoveLinks: true,
        acceptedFiles: ".gif,.jpg,.png",
        success: function (file, data) {
            var image = $("#imageInput").val();
            image += data.datas + ",";
            $("#imageInput").val(image);
        },
        init: function (file) {
            console.log(file);
        }
    });

    function style_edit_form(form) {
        form.find('input[name=sdate]').datepicker({
            format: 'yyyy-mm-dd',
            autoclose: true
        })
            .end().find('input[name=stock]')
            .addClass('ace ace-switch ace-switch-5').after('<span class="lbl"></span>');
        var buttons = form.next().find('.EditButton .fm-button');
        buttons.addClass('btn btn-sm').find('[class*="-icon"]').hide(); //ui-icon, s-icon
        buttons.eq(0).addClass('btn-primary').prepend('<i class=" fa fa-check"></i>');
        buttons.eq(1).prepend('<i class=" fa fa-times"></i>')

        buttons = form.next().find('.navButton a');
        buttons.find('.ui-icon').hide();
        buttons.eq(0).append('<i class=" fa fa-chevron-left"></i>');
        buttons.eq(1).append('<i class=" fa fa-chevron-right"></i>');
    }

    function style_delete_form(form) {
        var buttons = form.next().find('.EditButton .fm-button');
        buttons.addClass('btn btn-sm btn-white btn-round').find('[class*="-icon"]').hide(); //ui-icon, s-icon
        buttons.eq(0).addClass('btn-danger').prepend('<i class=" fa fa-trash-o"></i>');
        buttons.eq(1).addClass('btn-default').prepend('<i class=" fa fa-times"></i>')
    }

    function style_search_filters(form) {
        form.find('.delete-rule').val('X');
        form.find('.add-rule').addClass('btn btn-xs btn-primary');
        form.find('.add-group').addClass('btn btn-xs btn-success');
        form.find('.delete-group').addClass('btn btn-xs btn-danger');
    }

    function style_search_form(form) {
        var dialog = form.closest('.ui-jqdialog');
        var buttons = dialog.find('.EditTable')
        buttons.find('.EditButton a[id*="_reset"]').addClass('btn btn-sm btn-info').find('.ui-icon').attr('class', ' fa fa-retweet');
        buttons.find('.EditButton a[id*="_query"]').addClass('btn btn-sm btn-inverse').find('.ui-icon').attr('class', ' fa fa-comment-o');
        buttons.find('.EditButton a[id*="_search"]').addClass('btn btn-sm btn-purple').find('.ui-icon').attr('class', ' fa fa-search');
    }

    function beforeDeleteCallback(e) {
        var form = $(e[0]);
        if (form.data('styled'))
            return false;

        form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
        style_delete_form(form);

        form.data('styled', true);
    }

    function beforeEditCallback(e) {
        var form = $(e[0]);
        form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
        style_edit_form(form);
    }

    function updatePagerIcons(table) {
        var replacement = {
            'ui-icon-seek-first': ' fa fa-angle-double-left bigger-140',
            'ui-icon-seek-prev': ' fa fa-angle-left bigger-140',
            'ui-icon-seek-next': ' fa fa-angle-right bigger-140',
            'ui-icon-seek-end': ' fa fa-angle-double-right bigger-140'
        };
        $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function () {
            var icon = $(this);
            var $class =
                jQuery.trim(icon.attr('class').replace('ui-icon', ''));

            if ($class in
                replacement
            )
                icon.attr('class', 'ui-icon ' + replacement[$class]);
        })
    }

    function enableTooltips(table) {
        $('.navtable .ui-pg-button').tooltip({
            container: 'body'
        });
        $(table).find('.ui-pg-div').tooltip({
            container: 'body'
        });
    }


    /* PROGGRESS START */
    $.mpb("show", {value: [0, 50], speed: 5});
    /* END PROGGRESS START */

    var html_click_avail = true;

    $("html").on("click", function () {
        if (html_click_avail)
            $(".x-navigation-horizontal li,.x-navigation-minimized li").removeClass('active');
    });

    $(".x-navigation-horizontal .panel").on("click", function (e) {
        e.stopPropagation();
    });

    /* WIDGETS (DEMO)*/
    $(".widget-remove").on("click", function () {
        $(this).parents(".widget").fadeOut(400, function () {
            $(this).remove();
            $("body > .tooltip").remove();
        });
        return false;
    });
    /* END WIDGETS */

    /* Gallery Items */
    $(".gallery-item .iCheck-helper").on("click", function () {
        var wr = $(this).parent("div");
        if (wr.hasClass("checked")) {
            $(this).parents(".gallery-item").addClass("active");
        } else {
            $(this).parents(".gallery-item").removeClass("active");
        }
    });
    $(".gallery-item-remove").on("click", function () {
        $("body").showLoading();
        var id=$(this).parent("li").data("id")
        $.ajax({
            'url': "/banner/delete",
            'data':{'id':id},
            'dataType': 'json',
            'type': 'post',
            'success': function () {
                $("body").hideLoading();
                window.location.href="banner/list";
            },
            'error': function () {
                $("body").hideLoading();
            },
            'async': true
        });

        return false;
    });
    $(".gallery-item-edit").on("click", function () {
        $("body").showLoading();
        var id=$(this).parent("li").data("id")
        window.location.href="/banner/input?id="+id
    });
    $("#gallery-toggle-items").on("click", function () {

        $(".gallery-item").each(function () {

            var wr = $(this).find(".iCheck-helper").parent("div");

            if (wr.hasClass("checked")) {
                $(this).removeClass("active");
                wr.removeClass("checked");
                wr.find("input").prop("checked", false);
            } else {
                $(this).addClass("active");
                wr.addClass("checked");
                wr.find("input").prop("checked", true);
            }

        });

    });
    /* END Gallery Items */

    // XN PANEL DRAGGING
    $(".xn-panel-dragging").draggable({
        containment: ".page-content", handle: ".panel-heading", scroll: false,
        start: function (event, ui) {
            html_click_avail = false;
            $(this).addClass("dragged");
        },
        stop: function (event, ui) {
            $(this).resizable({
                maxHeight: 400,
                maxWidth: 600,
                minHeight: 200,
                minWidth: 200,
                helper: "resizable-helper",
                start: function (event, ui) {
                    html_click_avail = false;
                },
                stop: function (event, ui) {
                    $(this).find(".panel-body").height(ui.size.height - 82);
                    $(this).find(".scroll").mCustomScrollbar("update");

                    setTimeout(function () {
                        html_click_avail = true;
                    }, 1000);

                }
            })

            setTimeout(function () {
                html_click_avail = true;
            }, 1000);
        }
    });
    // END XN PANEL DRAGGING

    /* DROPDOWN TOGGLE */
    $(".dropdown-toggle").on("click", function () {
        onresize();
    });
    /* DROPDOWN TOGGLE */

    /* MESSAGE BOX */
    $(".mb-control").on("click", function () {
        var box = $($(this).data("box"));
        if (box.length > 0) {
            box.toggleClass("open");

            var sound = box.data("sound");

            if (sound === 'alert')
                playAudio('alert');

            if (sound === 'fail')
                playAudio('fail');

        }
        return false;
    });
    $(".mb-control-close").on("click", function () {
        $(this).parents(".message-box").removeClass("open");
        return false;
    });
    /* END MESSAGE BOX */

    /* CONTENT FRAME */
    $(".content-frame-left-toggle").on("click", function () {
        $(".content-frame-left").is(":visible")
            ? $(".content-frame-left").hide()
            : $(".content-frame-left").show();
        page_content_onresize();
    });
    $(".content-frame-right-toggle").on("click", function () {
        $(".content-frame-right").is(":visible")
            ? $(".content-frame-right").hide()
            : $(".content-frame-right").show();
        page_content_onresize();
    });
    /* END CONTENT FRAME */

    /* MAILBOX */
    $(".mail .mail-star").on("click", function () {
        $(this).toggleClass("starred");
    });

    $(".mail-checkall .iCheck-helper").on("click", function () {

        var prop = $(this).prev("input").prop("checked");

        $(".mail .mail-item").each(function () {
            var cl = $(this).find(".mail-checkbox > div");
            cl.toggleClass("checked", prop).find("input").prop("checked", prop);
        });

    });
    /* END MAILBOX */

    /* PANELS */

    $(".panel-fullscreen").on("click", function () {
        panel_fullscreen($(this).parents(".panel"));
        return false;
    });

    $(".panel-collapse").on("click", function () {
        panel_collapse($(this).parents(".panel"));
        $(this).parents(".dropdown").removeClass("open");
        return false;
    });
    $(".panel-remove").on("click", function () {
        panel_remove($(this).parents(".panel"));
        $(this).parents(".dropdown").removeClass("open");
        return false;
    });
    $(".panel-refresh").on("click", function () {
        var panel = $(this).parents(".panel");
        panel_refresh(panel);

        setTimeout(function () {
            panel_refresh(panel);
        }, 3000);

        $(this).parents(".dropdown").removeClass("open");
        return false;
    });
    /* EOF PANELS */

    /* ACCORDION */
    $(".accordion .panel-title a").on("click", function () {

        var blockOpen = $(this).attr("href");
        var accordion = $(this).parents(".accordion");
        var noCollapse = accordion.hasClass("accordion-dc");


        if ($(blockOpen).length > 0) {

            if ($(blockOpen).hasClass("panel-body-open")) {
                $(blockOpen).slideUp(200, function () {
                    $(this).removeClass("panel-body-open");
                });
            } else {
                $(blockOpen).slideDown(200, function () {
                    $(this).addClass("panel-body-open");
                });
            }

            if (!noCollapse) {
                accordion.find(".panel-body-open").not(blockOpen).slideUp(200, function () {
                    $(this).removeClass("panel-body-open");
                });
            }

            return false;
        }

    });
    /* EOF ACCORDION */

    /* DATATABLES/CONTENT HEIGHT FIX */
    $(".dataTables_length select").on("change", function () {
        onresize();
    });
    /* END DATATABLES/CONTENT HEIGHT FIX */

    /* TOGGLE FUNCTION */
    $(".toggle").on("click", function () {
        var elm = $("#" + $(this).data("toggle"));
        if (elm.is(":visible"))
            elm.addClass("hidden").removeClass("show");
        else
            elm.addClass("show").removeClass("hidden");

        return false;
    });
    /* END TOGGLE FUNCTION */

    /* MESSAGES LOADING */
    $(".messages .item").each(function (index) {
        var elm = $(this);
        setInterval(function () {
            elm.addClass("item-visible");
        }, index * 300);
    });
    /* END MESSAGES LOADING */

    x_navigation();
});

$(function () {
    onload();

    /* PROGGRESS COMPLETE */
    $.mpb("update", {
        value: 100, speed: 5, complete: function () {
            $(".mpb").fadeOut(200, function () {
                $(this).remove();
            });
        }
    });
    /* END PROGGRESS COMPLETE */
});

$(window).resize(function () {
    x_navigation_onresize();
    page_content_onresize();
});

function onload() {
    x_navigation_onresize();
    page_content_onresize();
}

function page_content_onresize() {
    $(".page-content,.content-frame-body,.content-frame-right,.content-frame-left").css("width", "").css("height", "");

    var content_minus = 0;
    content_minus = ($(".page-container-boxed").length > 0) ? 40 : content_minus;
    content_minus += ($(".page-navigation-top-fixed").length > 0) ? 50 : 0;

    var content = $(".page-content");
    var sidebar = $(".page-sidebar");

    if (content.height() < $(document).height() - content_minus) {
        content.height($(document).height() - content_minus);
    }

    if (sidebar.height() > content.height()) {
        content.height(sidebar.height());
    }

    if ($(window).width() > 1024) {

        if ($(".page-sidebar").hasClass("scroll")) {
            if ($("body").hasClass("page-container-boxed")) {
                var doc_height = $(document).height() - 40;
            } else {
                var doc_height = $(window).height();
            }
            $(".page-sidebar").height(doc_height);

        }

        if ($(".content-frame-body").height() < $(document).height() - 162) {
            $(".content-frame-body,.content-frame-right,.content-frame-left").height($(document).height() - 162);
        } else {
            $(".content-frame-right,.content-frame-left").height($(".content-frame-body").height());
        }

        $(".content-frame-left").show();
        $(".content-frame-right").show();
    } else {
        $(".content-frame-body").height($(".content-frame").height() - 80);

        if ($(".page-sidebar").hasClass("scroll"))
            $(".page-sidebar").css("height", "");
    }

    if ($(window).width() < 1200) {
        if ($("body").hasClass("page-container-boxed")) {
            $("body").removeClass("page-container-boxed").data("boxed", "1");
        }
    } else {
        if ($("body").data("boxed") === "1") {
            $("body").addClass("page-container-boxed").data("boxed", "");
        }
    }
}

/* PANEL FUNCTIONS */
function panel_fullscreen(panel) {

    if (panel.hasClass("panel-fullscreened")) {
        panel.removeClass("panel-fullscreened").unwrap();
        panel.find(".panel-body,.chart-holder").css("height", "");
        panel.find(".panel-fullscreen .fa").removeClass("fa-compress").addClass("fa-expand");

        $(window).resize();
    } else {
        var head = panel.find(".panel-heading");
        var body = panel.find(".panel-body");
        var footer = panel.find(".panel-footer");
        var hplus = 30;

        if (body.hasClass("panel-body-table") || body.hasClass("padding-0")) {
            hplus = 0;
        }
        if (head.length > 0) {
            hplus += head.height() + 21;
        }
        if (footer.length > 0) {
            hplus += footer.height() + 21;
        }

        panel.find(".panel-body,.chart-holder").height($(window).height() - hplus);


        panel.addClass("panel-fullscreened").wrap('<div class="panel-fullscreen-wrap"></div>');
        panel.find(".panel-fullscreen .fa").removeClass("fa-expand").addClass("fa-compress");

        $(window).resize();
    }
}

function panel_collapse(panel, action, callback) {

    if (panel.hasClass("panel-toggled")) {
        panel.removeClass("panel-toggled");

        panel.find(".panel-collapse .fa-angle-up").removeClass("fa-angle-up").addClass("fa-angle-down");

        if (action && action === "shown" && typeof callback === "function")
            callback();

        onload();

    } else {
        panel.addClass("panel-toggled");

        panel.find(".panel-collapse .fa-angle-down").removeClass("fa-angle-down").addClass("fa-angle-up");

        if (action && action === "hidden" && typeof callback === "function")
            callback();

        onload();

    }
}

function panel_refresh(panel, action, callback) {
    if (!panel.hasClass("panel-refreshing")) {
        panel.append('<div class="panel-refresh-layer"><img src="img/loaders/default.gif"/></div>');
        panel.find(".panel-refresh-layer").width(panel.width()).height(panel.height());
        panel.addClass("panel-refreshing");

        if (action && action === "shown" && typeof callback === "function")
            callback();
    } else {
        panel.find(".panel-refresh-layer").remove();
        panel.removeClass("panel-refreshing");

        if (action && action === "hidden" && typeof callback === "function")
            callback();
    }
    onload();
}

function panel_remove(panel, action, callback) {
    if (action && action === "before" && typeof callback === "function")
        callback();

    panel.animate({'opacity': 0}, 200, function () {
        panel.parent(".panel-fullscreen-wrap").remove();
        $(this).remove();
        if (action && action === "after" && typeof callback === "function")
            callback();


        onload();
    });
}

/* EOF PANEL FUNCTIONS */

/* X-NAVIGATION CONTROL FUNCTIONS */
function x_navigation_onresize() {

    var inner_port = window.innerWidth || $(document).width();

    if (inner_port < 1025) {
        $(".page-sidebar .x-navigation").removeClass("x-navigation-minimized");
        $(".page-container").removeClass("page-container-wide");
        $(".page-sidebar .x-navigation li.active").removeClass("active");


        $(".x-navigation-horizontal").each(function () {
            if (!$(this).hasClass("x-navigation-panel")) {
                $(".x-navigation-horizontal").addClass("x-navigation-h-holder").removeClass("x-navigation-horizontal");
            }
        });


    } else {
        if ($(".page-navigation-toggled").length > 0) {
            x_navigation_minimize("close");
        }

        $(".x-navigation-h-holder").addClass("x-navigation-horizontal").removeClass("x-navigation-h-holder");
    }

}

function x_navigation_minimize(action) {

    if (action == 'open') {
        $(".page-container").removeClass("page-container-wide");
        $(".page-sidebar .x-navigation").removeClass("x-navigation-minimized");
        $(".x-navigation-minimize").find(".fa").removeClass("fa-indent").addClass("fa-dedent");
        $(".page-sidebar.scroll").mCustomScrollbar("update");
    }

    if (action == 'close') {
        $(".page-container").addClass("page-container-wide");
        $(".page-sidebar .x-navigation").addClass("x-navigation-minimized");
        $(".x-navigation-minimize").find(".fa").removeClass("fa-dedent").addClass("fa-indent");
        $(".page-sidebar.scroll").mCustomScrollbar("disable", true);
    }

    $(".x-navigation li.active").removeClass("active");

}

function x_navigation() {

    $(".x-navigation-control").click(function () {
        $(this).parents(".x-navigation").toggleClass("x-navigation-open");

        onresize();

        return false;
    });

    if ($(".page-navigation-toggled").length > 0) {
        x_navigation_minimize("close");
    }

    $(".x-navigation-minimize").click(function () {

        if ($(".page-sidebar .x-navigation").hasClass("x-navigation-minimized")) {
            $(".page-container").removeClass("page-navigation-toggled");
            x_navigation_minimize("open");
        } else {
            $(".page-container").addClass("page-navigation-toggled");
            x_navigation_minimize("close");
        }

        onresize();

        return false;
    });

    $(".x-navigation  li > a").click(function () {

        var li = $(this).parent('li');
        var ul = li.parent("ul");

        ul.find(" > li").not(li).removeClass("active");

    });

    $(".x-navigation li").click(function (event) {
        event.stopPropagation();

        var li = $(this);

        if (li.children("ul").length > 0 || li.children(".panel").length > 0 || $(this).hasClass("xn-profile") > 0) {
            if (li.hasClass("active")) {
                li.removeClass("active");
                li.find("li.active").removeClass("active");
            } else
                li.addClass("active");

            onresize();

            if ($(this).hasClass("xn-profile") > 0)
                return true;
            else
                return false;
        }
    });

    /* XN-SEARCH */
    $(".xn-search").on("click", function () {
        $(this).find("input").focus();
    })
    /* END XN-SEARCH */

}

/* EOF X-NAVIGATION CONTROL FUNCTIONS */

/* PAGE ON RESIZE WITH TIMEOUT */
function onresize(timeout) {
    timeout = timeout ? timeout : 200;

    setTimeout(function () {
        page_content_onresize();
    }, timeout);
}

/* EOF PAGE ON RESIZE WITH TIMEOUT */

/* PLAY SOUND FUNCTION */
function playAudio(file) {
    if (file === 'alert')
        document.getElementById('audio-alert').play();

    if (file === 'fail')
        document.getElementById('audio-fail').play();
}

/* END PLAY SOUND FUNCTION */

/* NEW OBJECT(GET SIZE OF ARRAY) */
Object.size = function (obj) {
    var size = 0, key;
    for (key in obj) {
        if (obj.hasOwnProperty(key)) size++;
    }
    return size;
};
/* EOF NEW OBJECT(GET SIZE OF ARRAY) */